<?php

use yii\db\Migration;

/**
 * Class m230606_071038_rbac_furniture_place
 */
class m230606_071038_rbac_furniture_place extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $auth = Yii::$app->authManager;

        $permissionCreate = $auth->createPermission('createFurniturePlace');
        $auth->add($permissionCreate);

        $permissionUpdate = $auth->createPermission('updateFurniturePlace');
        $auth->add($permissionUpdate);

        $permissionDelete = $auth->createPermission('deleteFurniturePlace');
        $auth->add($permissionDelete);

        $permissionBrowse = $auth->createPermission('browseFurniturePlace');
        $auth->add($permissionBrowse);

        $userRole = $auth->createRole('furniturePlaceUser');
        $auth->add($userRole);

        $managerRole = $auth->createRole('furniturePlaceManager');
        $auth->add($managerRole);

        $auth->addChild($userRole, $permissionBrowse);

        $auth->addChild($managerRole, $permissionCreate);
        $auth->addChild($managerRole, $permissionUpdate);
        $auth->addChild($managerRole, $permissionDelete);
        $auth->addChild($managerRole, $permissionBrowse);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $auth = Yii::$app->authManager;

        $auth->remove($auth->getPermission('createFurniturePlace'));
        $auth->remove($auth->getPermission('updateFurniturePlace'));
        $auth->remove($auth->getPermission('deleteFurniturePlace'));
        $auth->remove($auth->getPermission('browseFurniturePlace'));
        $auth->remove($auth->getRole('furniturePlaceUser'));
        $auth->remove($auth->getRole('furniturePlaceManager'));
    }
}
